package service.impl;

import dao.SubjectDao;
import dao.impl.SubjectDaoImpl;
import model.Subject;
import service.SubjectService;

import java.util.List;

/**
 * @author wyt
 * @create 2022-12-17 14:44
 */
public class SubjectServiceImpl implements SubjectService {

    SubjectDao subjectDao=new SubjectDaoImpl();
    @Override
    public List<Subject> findByPage(int page, int pageSize) {
        return subjectDao.findByPage(page,pageSize);
    }

    @Override
    public List<Subject> findById(long sid, int page, int pageSize) {
        return subjectDao.findById(sid,page,pageSize);
    }


    @Override
    public List<Subject> findByName(String sname, int page, int pageSize) {
        return subjectDao.findByName(sname,page,pageSize);
    }

//    @Override
//    public Subject get(String id) {
//        if (id == null || id.equals("")) {
//            return null;
//        }
//        return get(Long.parseLong(id));
//    }

    @Override
    public Subject get(Long sid) {
        return subjectDao.get(sid);
    }

    @Override
    public int count() {
        return subjectDao.count();
    }



    @Override
    public int countByName(String sname) {
        return subjectDao.countByName(sname);
    }

    @Override
    public int countById(long sid) {
        return subjectDao.countById(sid);
    }

    @Override
    public boolean insert(Subject subject) {
        if (subject == null) {
            return false;
        }
        return subjectDao.insert(subject) == 1 ? true : false;
    }

    @Override
    public boolean delete(Long id_s,Long id_u) {
        if (id_s == null || id_s.equals("") ||id_u == null || id_u.equals("")) {
            return false;
        }
        return subjectDao.delete(id_u,id_s) == 1 ? true : false;
    }

    @Override
    public boolean update(Subject subject) {
        if (subject == null) {
            return false;
        }
        return subjectDao.update(subject) == 1 ? true : false;
    }

}
